package com.yunshipei.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.yunshipei.enterplorer.R;
import com.yunshipei.db.DatabaseUtil;
import com.yunshipei.model.NotifiDeleteModel;
import com.yunshipei.model.NotifyInfo;

import io.rong.eventbus.EventBus;

//import de.greenrobot.event.EventBus;

/**
 * Created by cike on 16/1/11.
 */
public class NotifiDestoryDeleteDialog extends Dialog{
    private View view = null;
    private TextView contextStr, cancel, ok;
    private NotifyInfo notifiInfo = null;
    private DatabaseUtil dbu = null;
    public NotifiDestoryDeleteDialog(Context context, NotifyInfo notifiInfo) {
        super(context);
        this.notifiInfo = notifiInfo;
        init(context);
    }

    public NotifiDestoryDeleteDialog(Context context, int themeResId, NotifyInfo notifiInfo) {
        super(context, themeResId);
        this.notifiInfo = notifiInfo;
        init(context);
    }

    protected NotifiDestoryDeleteDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private void init(Context context) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dbu = new DatabaseUtil();
        LayoutInflater layoutInflater = getLayoutInflater();
        view = layoutInflater.inflate(R.layout.destory_notifi_layout, null);
        contextStr = (TextView) view.findViewById(R.id.deleta_context);
        cancel = (TextView) view.findViewById(R.id.cancel);
        if (notifiInfo != null) {
            contextStr.setText(notifiInfo.getSpeechRecognition().getContent());
        }
        ok = (TextView) view.findViewById(R.id.ok);
        this.setContentView(view);
        this.setCanceledOnTouchOutside(true);
        Window dialogWindow = this.getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams params = dialogWindow.getAttributes();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.width = (int) (wm.getDefaultDisplay().getWidth() * 0.8);
        dialogWindow.setWindowAnimations(R.style.modify_photo_anim_style);
        dialogWindow.setAttributes(params);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NotifiDestoryDeleteDialog.this.dismiss();
            }
        });
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dbu.deleteNotifi(notifiInfo.get_id());
                EventBus.getDefault().post(new NotifiDeleteModel());
                NotifiDestoryDeleteDialog.this.dismiss();
            }
        });
    }

}
